{extend name="common@admin_base" /}

{block name="head_extends"}
<script type="application/javascript" src="/static/js/base.js"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;

        var useridDOM = $('#id');
        var usernameDOM = $('#groupName');
        var emailDOM = $('#status');

        //刷新按钮点击事件
        $("#search").on('click',function () {
            table.reload('articles', {
                where: { //设定异步数据接口的额外参数，任意设
                    id: useridDOM.val()
                    ,groupName: usernameDOM.val()
                    ,status:emailDOM.val()
                    //…
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        $('#reflash').on('click',function () {
            table.reload('articles', {
                where: { //设定异步数据接口的额外参数，任意设
                    id: useridDOM.val()
                    ,groupName: usernameDOM.val()
                    ,status:emailDOM.val()
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //工具栏监听
        table.on('tool(articles)', function(obj){
            var data = obj.data;
            var href = '{$_form.admin_group_detail}';
            if(obj.event === 'detail'){
                layer.open({
                    id:'id'+data.id,
                    title:'组权限内容',
                    area: ['1000px', '500px'],
                    offset: 'lt',
                    type: 2,
                    content: [href+data.id] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            } else if(obj.event === 'del'){
                layer.confirm('真的删除该组么', function(index){
                    $.ajax({
                        url:'{$_form.admin_group_del}',
                        data:{
                            id:data.id
                        },
                        method:'post',
                        success:function (data) {
                            obj.del();
                            console.log(data);
                        }
                    });
                    layer.close(index);
                });
            }else if(obj.event === 'forbidden'){
                j_ajax('{$_form.admin_group_update_status}',{
                    id:data.id
                    ,status:10
                },function (d) {
                    layer.msg(d.info);
                    if (d.msg == 1){
                        table.reload('articles', {
                            where: { //设定异步数据接口的额外参数，任意设
                                id: useridDOM.val()
                                ,groupName: usernameDOM.val()
                                ,status:emailDOM.val()
                            }
                            ,page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                    }
                })
            }else if(obj.event === 'enable'){
                j_ajax('{$_form.admin_group_update_status}',{
                    id:data.id
                    ,status:99
                },function (d) {
                    layer.msg(d.info);
                    if (d.msg == 1){
                        table.reload('articles', {
                            where: { //设定异步数据接口的额外参数，任意设
                                id: useridDOM.val()
                                ,groupName: usernameDOM.val()
                                ,status:emailDOM.val()
                            }
                            ,page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                    }
                })
            }
        });

        $("#add").on('click',function(){
            layer.open({
                title:'新增组',
                area: ['1000px', '500px'],
                offset: 't',
                type: 2,
                content: ['{$_form.admin_group_add}'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            });
        });
    });
</script>

{/block}
{block name="body"}
<div class="demoTable layui-form">
    搜索ID：
    <div class="layui-inline">
        <input class="layui-input" name="id" id="id" autocomplete="off">
    </div>
    组名：
    <div class="layui-inline">
        <input class="layui-input" name="groupName" id="groupName" autocomplete="off">
    </div>
    作者：
    <div class="layui-inline">
        <select name="status" id="status" autocomplete="off">
            <option value="" selected>全部</option>
            <option value="10">无效</option>
            <option value="99">有效</option>

        </select>
    </div>
    <button class="layui-btn" data-type="reload" id="search"><span class="layui-icon layui-icon-search"></span>搜索</button>
    <a id="add" class="layui-btn layui-bg-blue"><span class="layui-icon layui-icon-add-circle"></span>新增</a>
    <a id="reflash" class="layui-btn layui-btn-primary"><span class="layui-icon layui-icon-refresh"></span>刷新</a>
</div>
<table class="layui-table" lay-data="{ url:'{$_form.admin_group_list}', id:'articles', page: {layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], groups: 1 }}" lay-filter="articles">
    <thead>
    <tr>
        <th lay-data="{field:'id', minWidth:50, sort: true,width:50}">ID</th>
        <th lay-data="{field:'groupName', minWidth:150, sort: true,width:150}">组名</th>
        <th lay-data="{field:'createTime', minWidth:150, sort: true,width:200}">创建时间</th>
        <th lay-data="{field:'statusExplain', minWidth: 80,width:80}">状态</th>
        <th lay-data="{fixed: 'right', align:'center', toolbar: '#tool'}">操作</th>
    </tr>
    </thead>
</table>

<script type="text/html" id="get_author">
    {{#  if(d.userid == 0){ }}
    未知用户
    {{#  } else { }}
    {{d.user.trueName}}
    {{#  } }}
</script>

<script type="text/html" id="tool">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" id="{{d.id}}">查看</a>
    {{#  if(d.status == 99){ }}
    <a class="layui-btn layui-btn-xs" lay-event="forbidden" id="{{d.id}}">禁用</a>
        {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-bg-gray" lay-event="enable" id="{{d.id}}">启用</a>
        {{#  } }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" id="{{d.id}}">删除</a>
</script>
{/block}